package httpserver

import (
	"errors"
	_ "net/http/pprof"

	"github.com/gin-contrib/pprof"
	"github.com/gin-gonic/gin"
)

var routeMap = make(map[string]gin.HandlerFunc)

func Register(name string, cb gin.HandlerFunc) error {
	if _, ok := routeMap[name]; ok {
		return errors.New("HandlerFunc 已存在！")
	}
	routeMap[name] = cb
	return nil
}

func Run() {
	r := gin.Default()
	pprof.Register(r) // 性能
	for k, v := range routeMap {
		r.POST(k, v)
	}
	r.Run(":8000")
}
